﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.ManageOrder
{
    public partial class OrderList : System.Web.UI.Page
    {
        int pageSize = 15;
        public int page = 1;
        public IList<DealInfo> deallist = new List<DealInfo>();
        public DealInfoBLL deabll = new DealInfoBLL();
        public int sort = 0;
        public string orderby = " order by AddDate desc";//默认排序
        public int count = 0;//列表总数
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["page"]))
            {
                page = Convert.ToInt32(Request["page"]);
            }
            if (!IsPostBack || Request["xiugai"] == null || Request["xiugai"] == "")
            {
                Bind();
            }
            else if (Request["xiugai"] == "1")
            {
                UpdateState();
            }
            else
            {
                Search();
            }
        }

        public void Bind()
        {
            deallist = deabll.GetDealInfo(orderby, page, pageSize);
            count = deabll.GetDealInfo();
            
        }

        public string GetPager()
        {
            return EnPager.GetPager(count, pageSize, page, "");

        }
        public void UpdateState()
        {
            string ids = Request["chek"].ToString();
            int state = Convert.ToInt32(Request["select1"]);

            int m = deabll.UpdateState(ids, state);
            if (m != 0)
            {
                StringUtil.Alert("修改成功！", "/manage/ManageOrder/OrderList.aspx?page=" + page);
            }
            Bind();

        }

        //搜索
        public void Search()
        {
            string key = Request["txtKey"].ToString ();
            if (key != null && key != "")
            {
                key = StringUtil.checkStr(key);
                deallist = deabll.GetLike(key, page, pageSize);
                count = deabll.GetLike(key);
            }
            else
            {
                Bind();
            }
        }

        

        //排序
        protected void Button2_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt32(Request["sort"]);
            switch (i)
            {
                case 0 :
                    orderby =" order by AddDate desc";
                    break ;
                    
                case  1:
                    orderby = " order by AddDate asc";
                    break;
                case 2:
                    orderby = " order by TotalPrice desc ";
                    break;
                case 3:
                    orderby = " order by TotalPrice asc";
                    break;
                default :
                    orderby = " order by AddDate desc";
                    break; 
            }
            Bind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string key = Request["txtKey"].ToString();
            if (key != null && key != "")
            {
                key = StringUtil.checkStr(key);
                deallist = deabll.GetLike(key, page, pageSize);
                count = deabll.GetLike(key);
            }
            else
            {
                Bind();
            }
        }
    }
}
